package com.itheima.demo2;

import java.util.LinkedList;
import java.util.List;

public class Test {

    public static void getNum(List<Integer> list){
        for (int num : list){
            System.out.print(num + " ");
        }
        System.out.println();
    }

    public static void main(String[] args){
        boolean[] flag = new boolean[201];
        LinkedList<Integer> list = new LinkedList<>();
        for(int i = 0; i < 100; i++){
            list.add((int)(Math.random() * 200 + 1));
            if(flag[list.getLast()]) {
                list.removeLast();
                i--;
            }
            else{
                flag[list.getLast()] = true;
            }
        }
        getNum(list);
        while (list.size() != 1) {
            for(int i = 0; i < list.size(); i++){
                list.remove(i);
            }
            getNum(list);
        }
        System.out.println(list.get(0));
    }
}
